﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Entities;
using Business;
namespace ServicesDirectory.UserControl
{
    public partial class OrganisationDetail5 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData("248c0b28-8081-4189-86d8-060993efaffd", true);
            }
        }

        protected void RptSupportingMaterial_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var lbluser = e.Item.FindControl("lblAddedBy") as Label;
            if (lbluser != null)
            {
                var user = new UserBusiness();
                var getUser = user.GetUserById(lbluser.Text);
                if (getUser != null)
                    lbluser.Text = getUser.Account;
            }
            var lblDate = e.Item.FindControl("lblAddedDate") as Label;
            if (lblDate != null)
            {
                lblDate.Text = DateTime.Parse(lblDate.Text).ToString("dd-MM-yyyy");
            }
        }

        private void BindData(string organisationId, bool isActive)
        {
            var lstMaterial = SupportMaterialBusiness.Instance.ListSupportMaterial(organisationId, isActive);
            if (lstMaterial != null)
            {
                lblTotalPage.Text = lstMaterial.Count % 15 == 0 ? (lstMaterial.Count / 15).ToString(CultureInfo.InvariantCulture) : (lstMaterial.Count / 15 + 1).ToString(CultureInfo.InvariantCulture);
                rptSupportingMaterial.DataSource = SupportMaterialBusiness.Instance.PagingSupportingMaterial(int.Parse(txtPageNumber.Text, CultureInfo.InvariantCulture), 15, lstMaterial);
                rptSupportingMaterial.DataBind();
            }

        }

        protected void rptSupportingMaterial_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "EditSupporting")
            {
                Response.Redirect("ManagerSupportingMaterial.aspx?id=" + e.CommandArgument);
            }
        }
    }
}